package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.UserStudyPlansInfo;

import com.example.computer_exam_training_sys.service.UserStudyPlansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userstudyplans")
@CrossOrigin
public class UserStudyPlansController {
    @Autowired
    UserStudyPlansService userStudyPlansService;

    //http://localhost:8080/userstudyplans/all
    // 查询所有计划
    @GetMapping("/all")
    public List<UserStudyPlansInfo> findAll() {
        return userStudyPlansService.findall();
    }

    //http://localhost:8080/userstudyplans/finduserall?userid=1
    // 单个用户全内容查取
    @GetMapping("/finduserall")
    public List<UserStudyPlansInfo> findUserAll( Integer userid) {
        return  userStudyPlansService.finduserAll(userid);
    }

    //http://localhost:8080/userstudyplans/findbyid?planid=1
    // 按计划id查取
    @GetMapping("/findbyid")
    public UserStudyPlansInfo findbyid( int planid) {
        return userStudyPlansService.findplanById( planid);
    }

    //http://localhost:8080/userstudyplans/updateplanProgress
    // 更新进度
    @PostMapping("/updateplanProgress")
    public int updateplanProgress(Integer planId, Integer addProgress){
        return userStudyPlansService.updateplanProgress( planId, addProgress);
    }

    //http://localhost:8080/userstudyplans/updateplanStatus
    // 更新状态
    @PostMapping("/updateplanStatus")
    public int updateplanStatus(Integer planId, Integer status){
        return userStudyPlansService.updateplanStatus( planId, status);
    }

    //http://localhost:8080/userstudyplans/delete?planId=5
    //删除计划
    @GetMapping("/delete")
    public int deleteplanById(Integer planId){
        return userStudyPlansService.deleteplanById(planId);
    }

    //http://localhost:8080/userstudyplans/insert
    //创建计划
    @PostMapping("/insert")
    public int insert(@RequestBody UserStudyPlansInfo userStudyPlansInfo) {
        return userStudyPlansService.insert(userStudyPlansInfo);
    }







}
